<template>
  <star-horse-dialog :visible = "batchDialogTableVisible" :title = "dialogTitle" is-batch = "true" @merge = "merge"
                     @mergeDraft = "mergeDraft"
                     @reset = "resetForm">

    <el-form :model = "ruleForm" :rules = "rules" class = "demo-ruleForm" ref = "ruleForm">
      <el-table
          :data = "ruleForm.batchDataList"
          :row-class-name = "rowClassName"
          @selection-change = "handleDetailSelectionChange"
          border
          fit = "true"
          ref = "tb"
          v-loading = "loading"
      >
        <el-table-column align = "center" type = "selection" fixed = "left" width = "30"/>
        <el-table-column align = "center" label = "序号" prop = "xh" width = "50"></el-table-column>
        <el-table-column
            :formatter = "dataFormat"
            :show-overflow-tooltip = "true"
            label = "主键"
            min-width = "200px"
            prop = "idInformation"
            required
            sortable v-if = " false ">
          <template #default = "scope">
            <el-input-number clearable placeholder = "请输入主键"
                             v-model = "scope.row.idInformation"/>
          </template>
        </el-table-column>
        <el-table-column
            :formatter = "dataFormat"
            :show-overflow-tooltip = "true"
            label = "系统编号"
            min-width = "200px"
            prop = "dataNo"
            sortable
            v-if = " false ">
          <template #default = "scope">
            <el-form-item :prop = "'batchDataList.'+scope.$index+'.dataNo'" required>
              <el-input clearable placeholder = "请输入系统编号"
                        v-model = "scope.row.dataNo"></el-input>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column
            :formatter = "dataFormat"
            :show-overflow-tooltip = "true"
            label = "系统Logo"
            min-width = "200px"
            prop = "sysLogo"
            required
            sortable v-if = "true ">
          <template #default = "scope">
            <el-form-item :prop = "'batchDataList.'+scope.$index+'.sysLogo'" required>
              <el-select-v2 :options = "iconList" clearable
                            filterable = "true"
                            placeholder = "请选系统Logo图标"
                            v-model = "scope.row.sysLogo"
                            value-key = "menuIcon">
                <template #default = "{ item }">
                        <span style = "margin-right: 8px"> <user-icon :icon = "item.menuIcon"
                                                                      style = "vertical-align: middle;font-size: 16px"/> </span>
                  <span style = " font-size: 13px"> {{ item.label }} </span>
                </template>
              </el-select-v2>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column
            :formatter = "dataFormat"
            :show-overflow-tooltip = "true"
            label = "系统名称"
            min-width = "200px"
            prop = "sysName"
            required
            sortable v-if = "true ">
          <template #default = "scope">
            <el-form-item :prop = "'batchDataList.'+scope.$index+'.sysName'" required>
              <el-input clearable placeholder = "请输入系统名称"
                        v-model = "scope.row.sysName"></el-input>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column
            :formatter = "dataFormat"
            :show-overflow-tooltip = "true"
            label = "系统编码"
            min-width = "200px"
            prop = "sysCode"
            required
            sortable v-if = "true ">
          <template #default = "scope">
            <el-form-item :prop = "'batchDataList.'+scope.$index+'.sysCode'" required>
              <el-input clearable placeholder = "请输入系统编码"
                        v-model = "scope.row.sysCode"></el-input>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column
            :formatter = "dataFormat"
            :show-overflow-tooltip = "true"
            label = "系统描述"
            min-width = "200px"
            prop = "sysDesc"
            required
            sortable v-if = "true ">
          <template #default = "scope">
            <el-form-item :prop = "'batchDataList.'+scope.$index+'.sysDesc'">
              <el-input clearable placeholder = "请输入系统描述"
                        v-model = "scope.row.sysDesc"></el-input>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column
            :formatter = "dataFormat"
            :show-overflow-tooltip = "true"
            label = "创建人"
            min-width = "200px"
            prop = "createdBy"
            sortable
            v-if = " false ">
          <template #default = "scope">
            <el-input clearable placeholder = "请输入创建人"
                      v-model = "scope.row.createdBy"></el-input>
          </template>
        </el-table-column>
        <el-table-column
            :formatter = "dataFormat"
            :show-overflow-tooltip = "true"
            label = "修改人"
            min-width = "200px"
            prop = "updatedBy"
            sortable
            v-if = " false ">
          <template #default = "scope">
            <el-input clearable placeholder = "请输入修改人"
                      v-model = "scope.row.updatedBy"></el-input>
          </template>
        </el-table-column>
        <el-table-column
            :formatter = "dataFormat"
            :show-overflow-tooltip = "true"
            label = "创建日期"
            min-width = "200px"
            prop = "createdDate"
            sortable
            v-if = " false ">
          <template #default = "scope">
            <el-date-picker clearable placeholder = "请选择创建日期"
                            type = "date"
                            v-model = "scope.row.createdDate">
            </el-date-picker>
          </template>
        </el-table-column>
        <el-table-column
            :formatter = "dataFormat"
            :show-overflow-tooltip = "true"
            label = "修改日期"
            min-width = "200px"
            prop = "updatedDate"
            sortable
            v-if = " false ">
          <template #default = "scope">
            <el-date-picker clearable placeholder = "请选择修改日期"
                            type = "date"
                            v-model = "scope.row.updatedDate">
            </el-date-picker>
          </template>
        </el-table-column>
        <el-table-column
            :formatter = "dataFormat"
            :show-overflow-tooltip = "true"
            label = "是否删除 1 是 0否"
            min-width = "200px"
            prop = "isDel"
            sortable
            v-if = " false ">
          <template #default = "scope">
            <el-input-number clearable placeholder = "请输入是否删除 1 是 0否"
                             v-model = "scope.row.isDel"/>
          </template>
        </el-table-column>
        <el-table-column
            :formatter = "dataFormat"
            :show-overflow-tooltip = "true"
            label = "状态名称"
            min-width = "200px"
            prop = "statusName"
            sortable
            v-if = "false">
          <template #default = "scope">
            <el-input clearable placeholder = "请输入状态名称"
                      v-model = "scope.row.statusName"></el-input>
          </template>
        </el-table-column>
        <el-table-column
            :formatter = "dataFormat"
            :show-overflow-tooltip = "true"
            label = "状态状态"
            min-width = "200px"
            prop = "statusCode"
            sortable
            v-if = "true">
          <template #default = "scope">
            <el-form-item :prop = "'batchDataList.'+scope.$index+'.statusCode'" required>
              <el-select placeholder = "请选择系统状态" v-model = "scope.row.statusCode">
                <el-option
                    :key = "sitem.statusCode"
                    :label = "sitem.statusName"
                    :value = "sitem.statusCode"
                    clearable
                    v-for = "sitem in selectData"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column fixed = "right" label = "操作" min-width = "150px">
          <template #header = "scope">
            <span>操作</span>&nbsp;&nbsp;
            <el-button @click = "handleAddDetails(scope.row,1)" link size = "mini" type = "primary">
              <el-tooltip content = "添加一行">
                <user-icon icon = "plus" style = "vertical-align: middle;color:#409EFF;"/>
              </el-tooltip>
            </el-button>
          </template>
          <template #default = "scope">
            <el-button v-if = "scope.row.xh==ruleForm.batchDataList.length" @click = "handleAddDetails(scope.row,1)"
                       link size = "mini" type = "primary">
              <el-tooltip content = "添加一行">添加</el-tooltip>
            </el-button>
            <el-button @click = "handleAddDetails(scope.row,2)" link size = "mini" type = "danger">
              <el-tooltip content = "删除当前行">删除</el-tooltip>
            </el-button>
          </template>
        </el-table-column>
      </el-table>

    </el-form>
  </star-horse-dialog>

  <star-horse-dialog :visible = "dialogTableVisible" :title = "dialogTitle" @merge = "merge" @mergeDraft = "mergeDraft"
                     @reset = "resetForm">

    <el-form :model = "ruleForm" :rules = "rules" class = "demo-ruleForm" ref = "ruleForm">
      <el-form-item label = "主键" prop = "idInformation" v-if = "false">
        <el-input clearable placeholder = "请输入主键"
                  v-model = "ruleForm.idInformation"></el-input>
      </el-form-item>
      <el-form-item label = "上级系统" prop = "parentId"
                    v-if = "!false">
        <el-select clearable placeholder = "请选择上级系统"
                   v-model = "ruleForm.parentId">
          <el-option v-for = "item in informationsList" :value = "item.value" :key = "item.value" :label = "item.name"/>
        </el-select>
      </el-form-item>

      <el-form-item label = "系统名称" prop = "sysName"
                    required v-if = "!false">
        <el-input clearable placeholder = "请输入系统名称"
                  v-model = "ruleForm.sysName"></el-input>
      </el-form-item>
      <el-form-item label = "系统编号" prop = "dataNo"
                    v-if = "!true">
        <el-input clearable placeholder = "请输入系统编号"
                  v-model = "ruleForm.dataNo"></el-input>
      </el-form-item>

      <el-form-item label = "系统编码" prop = "sysCode"
                    required v-if = "!false">
        <el-input clearable placeholder = "请输入系统编码"
                  v-model = "ruleForm.sysCode"></el-input>
      </el-form-item>
      <el-form-item label = "系统序号" prop = "dataSort"
                    required v-if = "!false">
        <el-input-number clearable placeholder = "请输入系统序号"
                         v-model = "ruleForm.dataSort"></el-input-number>
      </el-form-item>
      <el-form-item label = "系统Logo" prop = "sysLogo"
                    required v-if = "!false">
        <el-popover placement = "bottom" :width = "550" :height = "350" trigger = "click">
          <template #reference>
            <el-input v-model = "ruleForm.sysLogo" placeholder = "请选系统Logo图标"/>
          </template>
          <ul class = "system-icon">
            <li v-for = "sdata in iconList" @click = "ruleForm.sysLogo=sdata.menuIcon"
                :class = "ruleForm.sysLogo==sdata.menuIcon?'icon-active':''">
              <el-tooltip :content = "sdata.label">
                <user-icon :icon = "sdata.menuIcon" style = "color:#409EFF;vertical-align: middle;font-size: 48px"/>
              </el-tooltip>
            </li>
          </ul>
        </el-popover>

      </el-form-item>
      <el-form-item label = "系统描述" prop = "sysDesc"
                    v-if = "!false">
        <el-input type = "textarea" clearable placeholder = "请输入系统描述"
                  v-model = "ruleForm.sysDesc"></el-input>
      </el-form-item>

      <el-form-item label = "创建人" prop = "createdBy"
                    v-if = "!true">
        <el-input clearable placeholder = "请输入创建人"
                  v-model = "ruleForm.createdBy"></el-input>
      </el-form-item>

      <el-form-item label = "修改人" prop = "updatedBy"
                    v-if = "!true">
        <el-input clearable placeholder = "请输入修改人"
                  v-model = "ruleForm.updatedBy"></el-input>
      </el-form-item>

      <el-form-item label = "创建日期" prop = "createdDate"
                    v-if = "!true">
        <el-date-picker clearable placeholder = "请选择创建日期" type = "date"
                        v-model = "ruleForm.createdDate">
        </el-date-picker>
      </el-form-item>

      <el-form-item label = "修改日期" prop = "updatedDate"
                    v-if = "!true">
        <el-date-picker clearable placeholder = "请选择修改日期" type = "date"
                        v-model = "ruleForm.updatedDate">
        </el-date-picker>
      </el-form-item>

      <el-form-item label = "是否删除 1 是 0否" prop = "isDel"
                    v-if = "!true">
        <el-input-number clearable placeholder = "请输入是否删除 1 是 0否"
                         v-model = "ruleForm.isDel"/>
      </el-form-item>

      <el-form-item label = "系统状态" prop = "statusName"
                    v-if = "!true">
        <el-input clearable placeholder = "请输入状态名称"
                  v-model = "ruleForm.statusName"></el-input>
      </el-form-item>

      <el-form-item label = "系统状态" prop = "statusCode"
                    v-if = "!false">
        <el-select placeholder = "请选择系统状态" v-model = "ruleForm.statusCode">
          <el-option
              :key = "sitem.statusCode"
              :label = "sitem.statusName"
              :value = "sitem.statusCode"
              clearable
              v-for = "sitem in selectData"
          >
          </el-option>
        </el-select>
      </el-form-item>
    </el-form>
  </star-horse-dialog>
  <star-horse-dialog :visible = "viewVisible" :title = "'查看数据'" :is-view = "true">

    <div class = "item" v-if = "ruleForm.parent">
      <label>上级系统:</label>
      <div class = "content">{{ ruleForm.parent?.sysName }}</div>
    </div>
    <div class = "item">
      <label>系统名称:</label>
      <div class = "content">{{ ruleForm.sysName }}</div>
    </div>


    <div class = "item">
      <label>系统编码:</label>
      <div class = "content">{{ ruleForm.sysCode }}</div>
    </div>
    <div class = "item">
      <label>系统序号:</label>
      <div class = "content">{{ ruleForm.dataSort }}</div>
    </div>
    <div class = "item">
      <label>系统描述:</label>
      <div class = "content">{{ ruleForm.sysDesc }}</div>
    </div>
    <div class = "item">
      <label>系统描述:</label>
      <div class = "content">{{ ruleForm.sysDesc }}</div>
    </div>
    <div class = "item">
      <label>系统Logo:</label>
      <div class = "content">
        <user-icon :icon = "ruleForm.sysLogo"
                   style = "vertical-align: middle;color:#e3e9f2;"/>
      </div>
    </div>
    <div class = "item">
      <label>状态名称:</label>
      <div class = "content">{{ ruleForm.statusName }}</div>
    </div>
    <div class = "item">
      <label>创建日期:</label>
      <div class = "content">{{ createDate(ruleForm.createdDate) }}</div>
    </div>
  </star-horse-dialog>
  <el-card class = "inner_content">
    <el-form class = "search_area" size = "mini">

      <el-form-item label = "系统名称">
        <el-input placeholder = "请输入系统名称" v-model = "searchForm.sysName"/>
      </el-form-item>
      <el-form-item label = "上级系统">
        <el-select placeholder = "请选择上级系统" v-model = "searchForm.parentId">
          <el-option v-for = "item in informationsList" :value = "item.value" :key = "item.value" :label = "item.name"/>
        </el-select>
      </el-form-item>
      <el-form-item label = "添加时间">
        <el-date-picker
            end-placeholder = "结束日期" placeholder = "请选择添加时间"
            range-separator = "到"
            start-placeholder = "开始日期"
            type = "daterange"
            v-model = "searchForm.createdDate"
        />
      </el-form-item>
      <el-form-item label = "     ">
        <el-button @click = "dataSearch" link type = "primary">
          <user-icon icon = "search" style = "vertical-align: middle;color:#e3e9f2;"/>
          <span style = "vertical-align: middle;"> 查询 </span>
        </el-button>
        <el-button @click = "dataSearch(1)" link small>
          <span style = "vertical-align: middle;"> 重置 </span>
        </el-button>
      </el-form-item>
    </el-form>
    <el-divider/>


    <star-horse-button-list
        :permission = "permission"
        :upload-url = "uploadUrl"
        @upload = "upload"
        @uploadProcess = "uploadProcess"
        @uploadError = "uploadError"
        @uploadSuccess = "uploadProcess"
        @btnOperation = "btnOperation"
    />
    <el-table
        :data = "dataList"
        :row-key = "getRowIdentity"
        @row-dblclick = "editData"
        @selection-change = "handleSelectionChange"
        border
        class = "data_table"
        fit = "true"
        highlight-current-row = "true"
        id = "informationsPo"
        ref = "multipleTable"
        stripe = "true">
      <el-table-column fixed width = "1"/>
      <el-table-column
          :reserve-selection = "true"
          align = "center"
          fixed = "left"
          type = "selection"
      />
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "主键"
          min-width = "200px"
          prop = "idInformation"
          sortable
          v-if = " false ">
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "系统名称"
          min-width = "200px"
          prop = "sysName"
          sortable
          v-if = "true ">
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "上级系统"
          min-width = "200px"
          prop = "parent"
          sortable
          v-if = "true ">
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "系统编码"
          min-width = "200px"
          prop = "sysCode"
          sortable
          v-if = "true ">
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "系统序号"
          min-width = "120px"
          prop = "dataSort"
          sortable
          v-if = "true ">
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "系统编号"
          min-width = "200px"
          prop = "dataNo"
          sortable
          v-if = " false ">
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "系统Logo"
          min-width = "200px"
          prop = "sysLogo"
          sortable
          v-if = "true ">
        <template #default = "scope">
          <user-icon :icon = "scope.row.sysLogo" style = "vertical-align: middle;color:#e3e9f2;"/>
        </template>
      </el-table-column>

      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "系统描述"
          min-width = "200px"
          prop = "sysDesc"
          sortable
          v-if = "true ">
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "创建人"
          min-width = "200px"
          prop = "createdBy"
          sortable
          v-if = " true ">
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "修改人"
          min-width = "200px"
          prop = "updatedBy"
          sortable
          v-if = " false ">
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "创建日期"
          min-width = "200px"
          prop = "createdDate"
          sortable
          v-if = " true ">
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "修改日期"
          min-width = "200px"
          prop = "updatedDate"
          sortable
          v-if = " false ">
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "是否删除 1 是 0否"
          min-width = "200px"
          prop = "isDel"
          sortable
          v-if = " false ">
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "状态名称"
          min-width = "200px"
          prop = "statusName"
          sortable
          v-if = "true ">
      </el-table-column>
      <el-table-column
          :formatter = "dataFormat"
          :show-overflow-tooltip = "true"
          label = "状态编码"
          min-width = "200px"
          prop = "statusCode"
          sortable
          v-if = " false ">
      </el-table-column>
      <el-table-column fixed = "right" label = "操作" min-width = "180px">
        <template #default = "scope">
          <el-button v-if = "permission.edit" @click = "editById(scope.row[primaryKey])" link title = ""
                     type = "primary">
            <el-tooltip content = "编辑">编辑</el-tooltip>
          </el-button>
          <el-button v-if = "permission.view" @click = "viewById(scope.row[primaryKey])" link title = ""
                     type = "primary">
            <el-tooltip content = "查看">查看</el-tooltip>
          </el-button>
          <el-button v-if = "permission.delete" @click = "deleteById(scope.row[primaryKey])" link title = ""
                     type = "danger">
            <el-tooltip content = "删除">删除</el-tooltip>
          </el-button>
        </template>
      </el-table-column>

    </el-table>
    <el-divider/>
    <el-pagination
        :total = "totalData"
        @current-change = "pageChangeClick"
        @size-change = "pageSizeClick"
        layout = "total, sizes, prev, pager, next, jumper"
        v-model:currentPage = "currentPage"
        v-model:page-size = "pageSize"
        v-model:pageCount = "totalPage"/>
  </el-card>

</template>
<style>

</style>
<script>
import icon from "../../assets/icon";

import {common} from "../../api/common";
import {ref} from "vue";
import {postRequest} from "@/api/star_horse";

export default {
  name: "InformationsEntity",

  mixins: [common],
  setup() {
    return {}
  },
  data() {
    const loadByPageUrl = ref("/system-config/system/informationsEntity/pageList");
    const mergeUrl = ref("/system-config/system/informationsEntity/merge");
    const mergeDraftUrl = ref("/system-config/system/informationsEntity/mergeDraft");
    const batchMergeUrl = ref("/system-config/system/informationsEntity/mergeBatch");
    const batchMergeDraftUrl = ref("/system-config/system/informationsEntity/mergeBatchDraft");
    const loadByIdUrl = ref("/system-config/system/informationsEntity/getById");
    const deleteUrl = ref("/system-config/system/informationsEntity/batchDeleteById");
    const exportAllUrl = ref("/system-config/system/informationsEntity/exportData");
    const downloadTemplateUrl = ref("/system-config/system/informationsEntity/downloadTemplate");
    const userConditionUrl = ref("/system-config/system/informationsEntity/getAllByCondition");
    const uploadUrl = "/system-config/system/informationsEntity/importData";
    const primaryKey = "idInformations";
    return {
      uploadUrl,
      loadByPageUrl,
      mergeUrl,
      mergeDraftUrl,
      batchMergeUrl,
      batchMergeDraftUrl,
      loadByIdUrl,
      deleteUrl,
      exportAllUrl,
      downloadTemplateUrl,
      userConditionUrl,
      primaryKey,
      iconList: icon,
      rules: {
        sysName: [{required: true, message: "必选项不能为空", trigger: "blur"}],
        sysCode: [{required: true, message: "必选项不能为空", trigger: "blur"}],
        dataSort: [{required: true, message: "必选项不能为空", trigger: "blur"}],
        sysLogo: [{required: true, message: "必选项不能为空", trigger: "blur"}],
        sysDesc: [{required: false, message: "必选项不能为空", trigger: "blur"}],
        statusCode: [{required: false, message: "必选项不能为空", trigger: "blur"}],
      },
      informationsList: []
    }
  },

  methods: {
    dataFormat(row, column, cellValue, index) {
      cellValue = this.commonDataFormat(row, column, cellValue, index);
      if (column.property == "parent") {
        return cellValue?.sysName;
      }
      return cellValue;

    },


    /**
     * 初始化数据
     */
    init: function () {
      let _this = this;
      this.dataList = [];
      this.selectData = [];
      this.loadByPage(this.currentPage, this.pageSize);
      this.commonSelectData("informationsUi");
      this.loadPermissionResources();
      postRequest(_this.userConditionUrl, [{propertyName: "statusCode", value: "1"}]).then(res => {
        let redata = res.data;
        if (redata.code == -1) {
          return;
        }
        _this.informationsList = [];
        redata.data.forEach(item => {
          _this.informationsList.push({name: item.sysName, value: item.idInformations})
        });
      });
    },

    parseSearchData: function () {
      let data = this.searchForm;
      let arr = [];
      if (data.sysName) {
        arr.push({
          propertyName: "sysName",
          value: data.sysName,
          operation: "lk"
        });
      }
      if (data.createdDate) {
        arr.push({
          propertyName: "createdDate",
          value: data.createdDate,
          operation: "bt"
        });
      }
      return arr;
    }

  },
  created() {
    this.init();
  }
}
</script>